<?php

/**
 * 公用控制器
 */
class Public_Controller extends Controller
{
    public function before()
    {
        //初始化视图引擎
        $this->view()->setLayout('layout');

        //设置 cookie 信息
        cookie::$domain = $_SERVER['HTTP_HOST'];
        cookie::$path = url::base();

        $_cookie = array ('user_id' => '11', 'role_id' => '4');
        cookie::set('login', $_cookie, 3600*6);

        $controller = Request::controller();
        $action = Request::action();

        //菜单权限检查
        $access = 'menu.'.$controller.'.'.$action;
        if (access::check(11, $access, $controller))
        {
            //echo '你有权限访问';
        } 
        elseif(access::check(11, 'core.admin')) 
        {
            //echo '超级管理员，你有权限访问';
        } 
        else
        {
            //echo '访问拒绝';
        }

        //赋值一些常用变量
        $this->view->set(array(
            'menus'     => Component::$menu,
            'userinfo'  => array('role_description' => 'Admin', 'user_id' => 'admin'),
            'action'    => Request::action(),
            'action_url'=> url::action(),
            'base_url'  => url::base(true),
            'asset_url' => url::asset(),
            'hash'      => safe::random(),
        ));
    }
}